package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.MRankBattleRecreationPO;
import com.yiyuan.app.mapper.MRankBattleRecreationMapper;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public class MRankBattleRecreationDAO extends BaseDAO<MRankBattleRecreationMapper, MRankBattleRecreationPO> {

    public List<MRankBattleRecreationPO> findBattleRankList() {
        LambdaQueryWrapper<MRankBattleRecreationPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankBattleRecreationPO::getIsRank, Boolean.TRUE);
        queryWrapper.eq(MRankBattleRecreationPO::getRankDate, LocalDate.now().minusDays(1));
        queryWrapper.orderByAsc(MRankBattleRecreationPO::getRankNo);
        return getBaseMapper().selectList(queryWrapper);
    }

    public MRankBattleRecreationPO findUserToday(LocalDate today, Long userId) {
        LambdaQueryWrapper<MRankBattleRecreationPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankBattleRecreationPO::getUserId, userId);
        queryWrapper.eq(MRankBattleRecreationPO::getRankDate, today);
        return getBaseMapper().selectOne(queryWrapper);
    }
}
